# coding: utf-8


def binary_tree(root):
    return [root, [], []]


def insert_left(root, branch):
    t = root.pop(1)
    if len(t) > 1:
        root.insert(1, [branch, t, []])
    else:
        root.insert(1, [branch, [], []])

    return root


def insert_right(root, branch):
    t = root.pop(2)
    if len(t) > 1:
        root.insert(2, [branch, [], t])
    else:
        root.insert(2, [branch, [], []])


def get_root_val(root):
    return root[0]


def set_root_val(root, value):
    root[0] = value


def get_left_child(root):
    return root[1]


def get_right_child(root):
    return root[2]


b = binary_tree(5)
insert_left(b, 3)
insert_left(b, 4)
insert_right(b, 100)
insert_right(b, 200)
print(b)

l = get_left_child(b)
print(l)

set_root_val(l, 8)
print(b)

insert_left(l, 16)
print(l)

insert_right(l, 32)
print(l)

print(get_left_child(get_left_child(b)))


def build_tree():
    r = binary_tree('a')
    insert_left(r, 'b')
    insert_right(get_left_child(r), 'd')

    insert_right(r, 'c')
    insert_left(get_right_child(r), 'e')
    insert_right(get_right_child(r), 'f')

    return r

print(build_tree())
